import { request } from '../utils/request'
const USER_BASE_URL = '/user'

interface LoginParams {
  username: string
  password: string
}

interface RegisterParams {
  username: string
  password: string
  email: string
}

// 用户相关api
export const userAPI = {
  // 用户登录
  login: (params: LoginParams): Promise<any> =>
    request({
      method: 'POST',
      url: `${USER_BASE_URL}/login`,
      data: params
    }).then((response) => response.data),

  // 用户注册
  register: (params: RegisterParams): Promise<any> =>
    request({
      method: 'POST',
      url: `${USER_BASE_URL}/register`,
      data: params
    }).then((response) => response.data),

  // 根据用户名或邮箱查询用户
  queryUser: (query: string): Promise<any> =>
    request({
      method: 'GET',
      url: `${USER_BASE_URL}/${query}`
    }),

  // 获取好友列表
  getFriendList: (userId: string): Promise<any> =>
    request({
      method: 'GET',
      url: `${USER_BASE_URL}/friend/${userId}`
    })
}
